import turtle
import time
1 # 准备二十四节气用到的数据
2 solar_terms_24 = []
3 names = ["雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种",
4 "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露",
5 "霜降", "立冬", "小雪", "大雪", "冬至", "小寒", "大寒", "立春"]
6 en_names = ["Rain Water", "Awakening of Insects", "Spring Equinox",
7 "Pure Brightness", "Grain Rain", "Beginning of Summer",
8 "Grain Buds", "Grain in Ear", "Summer Solstice", "Minor Heat",
9 "Major Heat", "Beginning of Autumn", "End of Heat", "White Dew",
10 "Autumn Equinox", "Cold Dew", "Frost's Descent",
11 "Beginning of Winter", "Minor Snow", "Major Snow", "Winter Solstice",12 "Minor Cold", "Major Cold", "Beginning of Spring"]
13 poems = ["随风潜入夜 润物细无声", "春雷响 万物长", "春风如贵客 一到便繁华",
14 "清明时节雨纷纷", "风吹雨洗一城花", "天地始交 万物并秀", "物至于此小得盈满",
15 "家家麦饭美 处处菱歌长", "绿筠尚含粉 圆荷始散芳", "荷风送香气 竹露滴清响",
16 "桂轮开子夜 萤火照空时", "天阶夜色凉如水 坐看牵牛织女星",
17 "春种一粒粟 秋收万颗子", "露从今夜白 月是故乡明", "晴空一鹤排云上",
18 "千家风扫叶 万里雁随阳", "霜叶红于二月花", "寒夜客来茶当酒",
19 "雪粉华 舞梨花", "大雪满弓刀", "冬至大如年", "凌寒独自开",
20 "燕山雪花大如席", "万紫千红总是春"]
21 for name, en_name, poem in zip(names, en_names, poems):
22 temp_dic = {}
23 temp_dic["NAME"] = name
24 temp_dic["EN_NAME"] = en_name
25 temp_dic["POEM"] = poem
26 solar_terms_24.append(temp_dic)
1 def draw_pic(secs):
2 # 清除窗口
3 turtle.clear()
4 # 绘制圆形，作为背景装饰
5 turtle.goto(0, -250)
6 turtle.fillcolor("#b1352b")
7 turtle.begin_fill()
8 turtle.circle(250)
9 turtle.end_fill()
10 turtle.home() # 画笔回到原点位置
11 turtle.penup() # 提起画笔，仍然可以写字，后面无需调用 pendown()函数放下画笔12 turtle.pencolor("white") # 将画笔颜色修改为白色
13 turtle.seth(-90) # 画笔朝下
14 # 写倒计时数字，即第一行文字
15 turtle.backward(10)
16 turtle.write(secs, align="center", font=("方正仿宋", 120, 'normal'))
17 # 写节气的中文名称，即第二行文字
18 turtle.forward(50)
19 name = solar_terms_24[24-secs]["NAME"]
20 turtle.write(name, align="center", font=("黑体", 30, 'normal'))
21 # 写节气的英文名称，即第三行文字
22 turtle.forward(50)
23 en_name = solar_terms_24[24-secs]["EN_NAME"]
24 turtle.write(en_name, align="center", font=("Arial", 25, 'normal'))
25 # 写节气对应的古诗词，即第四行文字
26 turtle.forward(50)
27 poem = solar_terms_24[24-secs]["POEM"]
28 turtle.write(poem, align="center", font=("隶书", 20, 'normal'))
29 turtle.home() # 画笔回到原点位置
def countdown(secs):
while secs > 0:
# 绘制倒计时画面
draw_pic(secs)
# 让程序睡眠一秒
time.sleep(1)
secs -= 1
turtle.speed(0) # 设置画笔移动的速度
turtle.delay(0) # 设置延迟时间，参数为 0 时表示绘图没有延迟
# 展示引导语
turtle.pencolor("black") # 设置画笔颜色为黑色
turtle.penup() # 提起画笔
turtle.setheading(-90) # 画笔朝下
turtle.backward(30) # 画笔移动到合适的位置
# 写中文引导语
turtle.write("让我们一起倒计时，迎接春的到来。", align="center",
font=("黑体", 20, 'normal'))
turtle.forward(60)
# 写英文引导语
turtle.write("Let's greet the arrival of spring with a countdown",
align="center", font=("Arial", 20, 'normal'))
turtle.home() # 画笔回到原点位置
time.sleep(3) # 暂停三秒钟，保证引导语画面能够正常显示
# 显示 24 秒倒计时
turtle.pencolor("white") # 设置画笔颜色为白色
# 定义倒计时秒数
seconds = 24
# 启动倒计时
countdown(seconds)
# 关闭画布
turtle.done()
